/*
package com.example.md.mddemo.easypoi;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.example.md.mddemo.entity.Customer;
import com.example.md.mddemo.entity.Person;
import com.example.md.mddemo.entity.value_obj.CustBankAcctInfo;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.junit.Assert;
import org.junit.Test;

import java.io.*;
import java.nio.file.Paths;
import java.util.*;

*/
/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * TODO:亲爱的临江仙，请写点注释吧...........
 * @Date 2018/8/14 14:05
 *//*

public class ExcelExportBigData {


    */
/**
     * 客户信息导出示例
     * @throws Exception
     *//*

    @Test
    public void CustmonerInfoExport() throws Exception{
        List<ExeclCustomer> list = getCustList();
        Date start = new Date();
        Workbook workbook = null;
        try {
            ExportParams params = new ExportParams("客户信息列表导出", "测试", ExcelType.XSSF);

            List<ExeclCustomer> templist = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                templist.add(list.get(i));
                if(i%500 == 0){
                   workbook = ExcelExportUtil.exportBigExcel(params, ExeclCustomer.class, templist);
                    templist.clear();
                }
            }
            ExcelExportUtil.closeExportBigExcel();

            System.out.println(new Date().getTime() - start.getTime());
            Date start2 = new Date();
            File savefile = new File("D:/excel/");
            if (!savefile.exists()) {
                savefile.mkdirs();
            }
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:/exceltest/test_cust_info.list.xlsx"));
            workbook.write(bos);
            bos.close();
            System.out.println(new Date().getTime() - start2.getTime());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    */
/**
     * 客户信息导入示例
     * @throws Exception
     *//*

    @Test
    public void CustmonerInfoInport() throws Exception {

        ImportParams params = new ImportParams();
        //设置标题页从第几行开始
        params.setTitleRows(1);
        //设置表头是第几行
        params.setHeadRows(2);
        //需要校验,支持JSR303标准,有个问题首行错误能获取到错误的list，不是首行的错误返回不了错误list
        params.setNeedVerfiy(true);
        params.setKeyIndex(5);
        params.setVerfiyGroup(new Class[]{ViliGroupOne.class});
        params.setVerifyHandler(new ExcelVerifyHandlerImpl());

        ExcelImportResult<ExcelVerifyEntityOfMode> execlCustomerList = ExcelImportUtil.importExcelMore(new FileInputStream(new File("D:\\exceltest\\test_cust_info.list.xlsx")),
                ExcelVerifyEntityOfMode.class,
                                                                            params);

        FileOutputStream fos = new FileOutputStream("D:/exceltest/baseHandlertest.xlsx");
        execlCustomerList.getWorkbook().write(fos);
        fos.close();
        for (int i = 0; i < execlCustomerList.getList().size(); i++) {
            System.out.println(ReflectionToStringBuilder.toString(execlCustomerList.getList().get(i)));
        }

        System.out.println("---------------------- fail -------------------");
        //如果要输出错误的数据行的话，配置错误的数据文件存放地址
        //如果简单粗暴，就直接判断错误execlCustomerList.getFailList().size()大于0的时候提醒格式错误，检查后重新导入
        fos = new FileOutputStream("D:/exceltest/ExcelVerifyFail.xlsx");
        execlCustomerList.getFailWorkbook().write(fos);
        fos.close();
        System.out.println(execlCustomerList.getFailWorkbook().getMissingCellPolicy().name());
        //失败的数据
        for (int i = 0; i < execlCustomerList.getFailList().size(); i++) {
            System.out.println(ReflectionToStringBuilder.toString(execlCustomerList.getFailList().get(i)));
        }

        System.out.println(execlCustomerList.getFailList().size());

//        Assert.assertEquals(49, execlCustomerList.getList().size());
    }




    private List<ExeclCustomer> getCustList() {

        List<ExeclCustomer> customerList = new ArrayList<>();

        for (int i = 0; i < 1000; i++) {

            ExeclCustomer execlCustomer = new ExeclCustomer();
            execlCustomer.setCustName("鹊桥仙"+i);
            execlCustomer.setCustType("自定义类型"+i);
            execlCustomer.setCustGradeName("品牌客户"+i);
            execlCustomer.setBalanceDate("2018-12");
            execlCustomer.setUserName("管理员"+i);
            execlCustomer.setGmtCreate(new Date());
            execlCustomer.setGmtModified(new Date());
            execlCustomer.setLegalPerson("水龙吟");
            execlCustomer.setIdentification("sbh123456789x");
            execlCustomer.setRemark("随便写一点备注"+i);


            //组装客户地址
            List<ExeclAddress> execlAddressList = new ArrayList<>();
            for (int j = 0; j < 2; j++) {
                ExeclAddress execlAddress = new ExeclAddress();
                execlAddress.setProvince("浙江省");
                execlAddress.setCity("杭州市");
                execlAddress.setCounty("西湖区");
                execlAddress.setOther("西溪首座A-1-1-310");
                execlAddressList.add(execlAddress);
            }

            execlCustomer.setAddressList(execlAddressList);


            //组装银行信息
            List<ExeclCustBankAcctInfo> execlCustBankAcctInfoList = new ArrayList<>();
            for (int j = 0; j < 3;  j++) {
                ExeclCustBankAcctInfo execlCustBankAcctInfo = new ExeclCustBankAcctInfo();
                execlCustBankAcctInfo.setBankAccount("5468721324674321");
                execlCustBankAcctInfo.setOpenAccountBank("农业银行");
                execlCustBankAcctInfoList.add(execlCustBankAcctInfo);
            }
            execlCustomer.setBankInfoList(execlCustBankAcctInfoList);

            //组装联系人信息
            List<ExeclCustContactPerson> contactPersonList = new ArrayList<>();
            for (int j = 0; j < 4; j++) {
                ExeclCustContactPerson execlCustContactPerson = new ExeclCustContactPerson();
                execlCustContactPerson.setContactAddress("江苏省南京市");
                execlCustContactPerson.setContactName("三台"+j);
                execlCustContactPerson.setPhoneNumber("13988887777");
                execlCustContactPerson.setFixedTelephone("0687-456123");
                execlCustContactPerson.setOtherNumber("123456"+j);
                execlCustContactPerson.setIsMain("否");
                contactPersonList.add(execlCustContactPerson);
            }
            execlCustomer.setContactList(contactPersonList);

            customerList.add(execlCustomer);

        }

        return  customerList;

    }








    */
/**
     *  基本格式，数据比较多的情况下导出
     * @throws Exception
     *//*

    @Test
    public void bigDataExport() throws Exception {

        List<Person> list = new ArrayList<>();
        Workbook workbook = null;
        Date start = new Date();
        ExportParams params = new ExportParams("千讯科技ERP导出","用户基本信息");
        for (int i = 0; i < 50000; i++) {
            Person client = new Person();
            Map<String, String> map = new HashMap<>();
            map.put("key"+i,"value"+1);


            client.setName("临江仙" + i);
            client.setAge(i++);
            client.setDes(map);

            list.add(client);
            if(list.size() == 10000){
                workbook = ExcelExportUtil.exportBigExcel(params, Person.class, list);
                list.clear();
            }
        }
        ExcelExportUtil.closeExportBigExcel();
        System.out.println(new Date().getTime() - start.getTime());
        File savefile = new File("D:/exceltest/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("D:/exceltest/test001.bigdata.xlsx");
        workbook.write(fos);
        fos.close();
    }


    */
/**
     * 带有list集合的数据导出
     * @throws Exception
     *//*

    @Test
    public void ListDataExport() throws Exception {

        List<Customer> list = getList();

        try {
            ExportParams params = new ExportParams("客户信息列表导出", "测试", ExcelType.XSSF);
            Workbook workbook = ExcelExportUtil.exportExcel(params, Customer.class, list);
            File savefile = new File("D:/excel/");
            if (!savefile.exists()) {
                savefile.mkdirs();
            }
            FileOutputStream fos = new FileOutputStream("D:/exceltest/test002.list.xlsx");
            workbook.write(fos);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public List<Customer> getList() {

        List<Customer> list = new ArrayList<>();
        Customer customer = new Customer();
        for (int i = 0; i < 10; i++) {

            //客户基本信息
            customer = new Customer();
            customer.setCustCode("custcode"+i);
            customer.setCustName("客户名称"+i);
            customer.setBalanceDate(new Date());


            //地址信息
            customer.getAddressList().add(new String("123321"));
            customer.getAddressList().add(new String("地址信息2"));


            //银行基本信息
            CustBankAcctInfo custBankAcctInfo = new CustBankAcctInfo();
            custBankAcctInfo.setBankAccount("2178301230187");
            custBankAcctInfo.setOpenAccountBank("农业银行");
            customer.getBankAcctInfoList().add(custBankAcctInfo);

            custBankAcctInfo = new CustBankAcctInfo();
            custBankAcctInfo.setBankAccount("9898462783213");
            custBankAcctInfo.setOpenAccountBank("建设银行");
            customer.getBankAcctInfoList().add(custBankAcctInfo);

            list.add(customer);

        }

        //最后一个客户银行信息加一个
        CustBankAcctInfo custBankAcctInfo = new CustBankAcctInfo();
        custBankAcctInfo.setBankAccount("42353434234124");
        custBankAcctInfo.setOpenAccountBank("工商银行");
        customer.getBankAcctInfoList().add(custBankAcctInfo);

        return list;

    }
}
*/
